package cn.smart.epic.config.properties;

import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @Auther Uncle_Z
 * @date 2017/9/6 20:06
 * @Email:2545375@qq.com
 * @Descrition epic项目配置
 * @since 1.0
 */

@Component
@ConfigurationProperties(prefix = EpicProperties.PREFIX)
public class EpicProperties {

    public static final String PREFIX = "epic";

    private boolean kaptchaOpen = false;
    private String fileUploadPath;
    private boolean haveCreatePath = false;
    private boolean springSessionOpen = false;
    private Integer sessionInvalidateTime = 30 * 60;  //session 失效时间（默认为30分钟 单位：秒）

    private Integer sessionValidationInterval = 15 * 60;  //session 验证失效时间（默认为15分钟 单位：秒）

    public boolean isKaptchaOpen() {
        return kaptchaOpen;
    }

    public void setKaptchaOpen(boolean kaptchaOpen) {
        this.kaptchaOpen = kaptchaOpen;
    }

    public String getFileUploadPath() {
        if (StringUtils.isEmpty(fileUploadPath)) {
            return System.getProperty("java.io.tmpdir");
        } else {
            if (!fileUploadPath.endsWith(File.separator)) {
                fileUploadPath = fileUploadPath + File.separator;
            }
            if (haveCreatePath == false) {
                File file = new File(fileUploadPath);
                file.mkdirs();
                haveCreatePath = true;
            }
            return fileUploadPath;
        }

    }

    public void setFileUploadPath(String fileUploadPath) {
        this.fileUploadPath = fileUploadPath;
    }

    public boolean isHaveCreatePath() {
        return haveCreatePath;
    }

    public void setHaveCreatePath(boolean haveCreatePath) {
        this.haveCreatePath = haveCreatePath;
    }

    public boolean isSpringSessionOpen() {
        return springSessionOpen;
    }

    public void setSpringSessionOpen(boolean springSessionOpen) {
        this.springSessionOpen = springSessionOpen;
    }

    public Integer getSessionInvalidateTime() {
        return sessionInvalidateTime;
    }

    public void setSessionInvalidateTime(Integer sessionInvalidateTime) {
        this.sessionInvalidateTime = sessionInvalidateTime;
    }

    public Integer getSessionValidationInterval() {
        return sessionValidationInterval;
    }

    public void setSessionValidationInterval(Integer sessionValidationInterval) {
        this.sessionValidationInterval = sessionValidationInterval;
    }
}
